CREATE OR REPLACE PROCEDURE KopiujLoty is

newFlightPlanId number;

cursor flightPlans is 
select fp.id, code, departuretime, arrivaltime, standardlagguageweight, flightid, flighttypeid, flightrouteid, flightstatusid
from flightplan fp
join flighttype ft on fp.flighttypeid = ft.id
where ft.type = 'rejsowy'
and departuretime  > SYSDATE - 7;

begin
  
  for flightPlan in flightPlans loop
    newFlightPlanId := FlightPlan_seq.nextval;
    insert into FlightPlan(id, code, departuretime, arrivaltime, standardlagguageweight, flightid, flighttypeid, flightrouteid, flightstatusid)
    values(newFlightPlanId, flightPlan.code, flightplan.departuretime + 7, flightplan.arrivaltime + 7, flightPlan.standardlagguageweight, flightPlan.flightid, flightPlan.flighttypeid, flightPlan.flightrouteid, flightPlan.flightstatusid);
    
    insert into FlightClassPrice(id, price, classId, flightPlanId) select FlightClassPrice_seq.nextval, price, classId, newFlightPlanId from FlightClassPrice where flightPlanId = flightPlan.id;

  end loop;

end;